var app = getApp(), api = getApp().api;

Page({
    data: {
        tabs: [ "全部", "审核中", "已通过", "已拒绝" ],
        activeIndex: 0,
        page: 1,
        refresh_top: !1,
        list: [],
    },

    onLoad: function (t) {
        getApp().page.onLoad(this, t);
        var a = this;
        a.reload()
    },
    reload: function(t) {
        var i = this, p = i.data.page, u = i.data.list;
        getApp().core.showLoading({
            title: "加载中"
        }), getApp().request({
            url: getApp().api.mch.article.list,
            data: {
                page: p,
                limit: 10
            },
            success: function(t) {
                console.log(t), i.setData({
                    page: p + 1
                }), t.data.length < 10 ? i.setData({
                    refresh_top: !0
                }) : i.setData({
                    refresh_top: !1
                }), u = u.concat(t.data), console.log(u);
                var e = [], a = [], o = [];
                for (var n in t.data) t.data[n].addtime = i.ormatDate(t.data[n].addtime).slice(0, 16), 
                t.data[n].img = t.data[n].img.split(",").slice(0, 4);
                i.setData({
                    list: u
                })
            },
            complete: function(t){
                getApp().core.hideLoading()
            }
        })
    },
    see: function(t) {
        console.log(t), console.log(this.data);
        var e = this.data.list, a = t.currentTarget.dataset.id;
        for (var o in e) if (e[o].id == a) var n = e[o];
        console.log(n), wx.navigateTo({
            url: "/pages/article-detail/article-detail?id=" + n.id,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    ormatDate: function(t) {
        var e = new Date(1e3 * t);
        return e.getFullYear() + "-" + a(e.getMonth() + 1, 2) + "-" + a(e.getDate(), 2) + " " + a(e.getHours(), 2) + ":" + a(e.getMinutes(), 2) + ":" + a(e.getSeconds(), 2);
        function a(t, e) {
            for (var a = "" + t, o = a.length, n = "", s = e; s-- > o; ) n += "0";
            return n + a;
        }
    },
    bianji: function(t) {
        console.log(t);
        var e = t.currentTarget.dataset.id;
        console.log(e), app.core.navigateTo({
            url: "modify?id=" + e,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    cancel: function(a) {
        var o = this;
        app.core.showModal({
            title: "提示",
            content: "是否删除帖子",
            showCancel: !0,
            cancelText: "取消",
            confirmText: "确定",
            success: function(t) {
                if (t.confirm) {
                    console.log("用户点击确定");
                    var e = a.currentTarget.dataset.id;
                    app.request({
                        url: api.mch.article.delete,
                        cachetime: "0",
                        data: {
                            id: e
                        },
                        success: function(t) {
                            console.log(t), 0 == t.code && (o.setData({
                                activeIndex: 0,
                                refresh_top: !1,
                                list: [],
                                page: 1
                            }), o.reload());
                        }
                    })
                }
            }
        })
    },
    shuaxin: function(t) {
        var a = this, o = t.currentTarget.dataset.id;
        app.core.showModal({
            title: '提示',
            content: "刷新此帖子？",
            confirmText: "确定刷新",
            success: function(t) {
                if(t.confirm) {
                    console.log("用户点击确定");
                    app.request({
                        url: api.mch.article.refresh,
                        data: {
                            id: o
                        },
                        success: function(e) {
                            console.log(e), 0 == e.code ? (app.core.showToast({
                                title: "刷新成功"
                            }), setTimeout(function() {
                                app.core.reLaunch({
                                    url: "/pages/article-list/article-list"
                                })
                            }, 1e3)) : app.core.showToast({
                                title: e.msg
                            }) 
                        }
                    })
                } else {
                    console.log("用户点击取消")
                }
            }
        })
    },
    gomch: function(t) {
        var a = this, o = t.currentTarget.dataset.mch_id;
        app.core.navigateTo({
            url: '/mch/shop/shop?mch_id=' + o
        })
    },
    onReady: function () {
    },
    onShow: function () {
    },
    onHide: function () {
    },
    onUnload: function () {
    },
    onPullDownRefresh: function () {
        this.setData({
            refresh_top: !1,
            list: [],
            page: 1
        }), this.reload(), wx.stopPullDownRefresh();
    },
    onReachBottom: function () {
        console.log("上拉加载", this.data.page), 0 == this.data.refresh_top && this.reload();
    },
    onShareAppMessage: function () {
    }
})